package com.zjsy.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zjsy.dao.MainNewsDao;
import com.zjsy.dao.WeChatNewsDao;
import com.zjsy.page.PageBean;
import com.zjsy.page.PageConstants;
import com.zjsy.po.MainNewsList;
import com.zjsy.po.WeChatNews;
import com.zjsy.po.WeChatNewsList;
import com.zjsy.service.WeChatNewService;
@Service
@Transactional
public class WeChatNewServiceImpl implements WeChatNewService {
	
	@Autowired
	private  WeChatNewsDao wechatNewsDao;

	@Override
	public List<WeChatNewsList> findWeChatNews() {
		// TODO Auto-generated method stub
		return wechatNewsDao.findWeChatNews();
	}

	@Override
	public PageBean<WeChatNewsList> findWeChatNewsByPage(int pc) {
		
		int ps = PageConstants.BOOK_PAGE_SIZE;
		int min = (pc-1)*ps;
		int max = ps;
		//得到beanList
		List<WeChatNewsList> beanLsit = wechatNewsDao.findWeChatNewsByPage(min, max);
		//得到所有的记录数
		int tr = wechatNewsDao.findWeChatNews().size();
		PageBean<WeChatNewsList> pb = new PageBean<>();
		pb.setBeanList(beanLsit);
		pb.setPc(pc);
		pb.setPs(ps);
		pb.setTr(tr);
		return pb;
		
	}

	@Override
	public void addWeChatNews(WeChatNews wechatnews) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
		wechatnews.setUptime(df.format(new Date()));// new Date()为获取当前系统时间
		wechatNewsDao.addWeChatNews(wechatnews);
		
	}

	@Override
	public WeChatNews   findWechatNewsById(String id) {
		
		return wechatNewsDao.findWechatNewsById(id);
	}

	@Override
	public void updateWeChatNewsById(WeChatNews WeChatNews) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
		WeChatNews.setUptime(df.format(new Date()));// new Date()为获取当前系统时间
	
		wechatNewsDao.updateWeChatNewsById(WeChatNews);
		
	}

	@Override
	public void deleteWeChatNewsById(String id) {
		
		wechatNewsDao.deleteWeChatNewsById(id);
	}

	

}
